package cn.index.dev.tech.config;

import cn.index.dev.tech.api.response.Response;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.multipart.MaxUploadSizeExceededException;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(MaxUploadSizeExceededException.class)
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    public Response<String> handleMaxUploadSizeExceeded(MaxUploadSizeExceededException ex) {
        return Response.<String>builder()
                .code("9999")
                .info("文件超过大小限制，请减小文件或联系管理员提高上传限额")
                .build();
    }
}

